import { HttpClient } from '@angular/common/http';
import { Component, ElementRef, Injector, OnInit, ViewChild } from '@angular/core';
import { ListBase } from 'app/modules/base/list-base';
import { MySelection } from 'app/modules/base/selection';
import { ListService } from 'app/modules/zone/services/list.service';
import { Zone, ZoneService } from 'app/modules/zone/services/zone.service';

@Component({
  selector: 'm-select-zone',
  templateUrl: './select-zone.component.html',
  styleUrls: ['./select-zone.component.scss'],
})
export class SelectZoneComponent extends ListBase implements OnInit {
  data

  @ViewChild('body') body: ElementRef;
  constructor(private injector: Injector, private zoneManager: ZoneService,public http:HttpClient) {
    super(injector);
    this.http.get('api/admin/batch_areas').subscribe((res: any) => {
      this.data = res.message;
    });
  }

  public list: Zone[];
  private primaryKey: keyof Zone;
  public selectionZone = new MySelection<Zone>(this.primaryKey);

  ngOnInit() {
    this.primaryKey = 'id';
    this.selectionZone = new MySelection<Zone>(this.primaryKey);
    this.zoneManager.tree().then(tree => {
      this.list = tree;
    });
  }

  log(e){
    this.selectionZone.selected = e
  }

  roll(e){
    this.body.nativeElement.scrollTop = e
  }
}
